package com.itheima.dao;

import com.itheima.pojo.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 吴
 * @version V1.0
 * @Description  权限
 * @Package com.itheima.dao
 * @date 2021/11/28 14:55
 */
public interface PermissionDao1 {

    /**
     * 根据角色ID查询所有权限名
     * @param roleId 角色ID
     * @return
     */
    List<Permission> findByRoleId(Integer roleId);


    /**
     * 查询所有权限名
     *
     * @return the list
     */
    @Select("select * from t_permission ")
    List<Map<String,Object>> findAllPermission();

    /**
     * 为角色添加权限
     *
     * @param permissionId the permission
     * @param roleId the roleId
     */
    void setRoleAndPermission(@Param("roleId") Integer roleId, @Param("permissionId") Integer permissionId);

    /**
     * 根据角色id查询权限id
     * @param roleId
     * @return
     */
    @Select("select p.id  from t_role_permission rp,t_permission p where rp.role_id=#{roleId} and p.id=rp.permission_id ")
    Integer[] findPermissionIdByRoleId(Integer roleId);

    /**
     * 根据角色id删除中间表
     * @param roleId
     */
    @Delete("delete from t_role_permission where t_role_permission.role_id=#{roleId}")
    void deleteRoleAndPermissionById(Integer roleId);


    /**
     * 根据角色id删除权限
     *
     * @param roleId the role id
     */
    @Delete("delete from t_role_permission where t_role_permission.role_id=#{roleId}")
    void deletePermissionById(Integer roleId);

    /**
     * 根据角色id添加权限
     *
     * @param permissionId1 the permission id 1
     * @param roleId        the role id
     */
    @Insert("insert into t_role_permission values(#{roleId},#{permissionId1})")
    void addPermissionById(@Param("permissionId1") Integer permissionId1, @Param("roleId") Integer roleId);
}
